/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include <iostream>

#include "Player.h"
#include "Melee.h"
#include "Shotgun.h"
#include "PlayerController.h"
#include "../Kernel.h"

extern Kernel* g_kernel;

/*-------------------------------------------------------------
    Define shortcuts
--------------------------------------------------------------*/
#define JOYSTICK_XAXIS ( g_kernel->GetInput()->GetJoystickX() )
#define JOYSTICK_YAXIS ( g_kernel->GetInput()->GetJoystickY() )

#define JOYSTICK_BUTTON( str ) ( g_kernel->GetInput()->IsJoystickButtonDown( g_kernel->GetCvars()->GetFloatValue( str ) ) )
#define KEY_BUTTON( str ) ( g_kernel->GetInput()->IsKeyDown( g_kernel->GetCvars()->GetFloatValue( str ) ) )
#define KEY_BUTTONSTAMP( str ) ( g_kernel->GetInput()->IsKeyDown( g_kernel->GetCvars()->GetFloatValue( str ), true ) )

/*------------------------------------------------------------
    Player Class
-------------------------------------------------------------*/

#define TIME (g_kernel->GetTime())

Player::Player(void) : IEntity()
{
    // button pressed
    buttons.btnPressed = 0;
    buttons.btnReleased = 0;
    buttons.buttons = 0;

    m_readInput = true;
    // next update
    m_nextUpdate = 0.0f;

    // register the config
    m_config.Register();

    // -----------add states-------------------
    // NOTE: States will be changed by the
    // PlayerController, the Player class acts
    // as a holder and executer of the current state
    // the controller will read input by the user, and
    // determine which state to make the player
    // ----------------------------------------

    m_entCtrl.SetEntity( this );
    m_FSM.SetOwner( this );
    SetFace(SOUTH);

    /** 
        Add weapons Temporarly for testing 
    */
    m_weaponMelee = new Melee;
    m_weaponMelee->CollideWith( this );
    m_weaponShotgun = new Shotgun;
    m_weaponShotgun->CollideWith( this );
    m_weaponInventory.NextItem();
}

/**
=============================
Update the current state
=============================
*/
void Player::Update(long dt)
{
    IEntity::Update( dt );
}

/** Damage this entity */
int Player::Damage( int hit )
{
    // old health
    int old = IEntity::Damage( hit );
    // return old health
    return old;
}


void Player::Trigger() 
{
    // do nothing
}

/** Collide with another entity */
bool Player::CollideWith( IEntity* ent )
{
    return false;
}
 

/** Pick Up an Item */
void Player::PickUpItem(IEntity* ent)
{
    IEntity::PickUpItem( ent );
}

Player::~Player(void)
{
    m_config.Save();
}











